#include "trackdataparser.h"
#include <QDebug>
TrackDataParser::TrackDataParser()
{

}

TrackDataParser::parseTrackData_FromUDP(unsigned char *buffer, int buffer_size, TargetMessageStruct *track_buffer, int track_size)
{
    Track_Out_CR elem_topush;
    for (std::size_t i = 0; i < track_size; i++)
    {
        memcpy(&elem_topush, buffer+i*sizeof(Track_Out_CR), sizeof(Track_Out_CR));
        track_buffer[i].Amp = 0;
        track_buffer[i].Angle = (float)elem_topush.Track_Azimuth*data_precision;///360.0*2.0f*pi;
        track_buffer[i].BatchID = elem_topush.Track_ID;
        track_buffer[i].CourseAngle = 0;
        track_buffer[i].Distance = elem_topush.Track_Range*data_precision;
        track_buffer[i].Radius = 0;
        track_buffer[i].Speed = elem_topush.Track_Velocity*data_precision;
        //qDebug() << "(id, R, A) = (" <<track_buffer[i].BatchID <<", "<<track_buffer[i].Distance << ","<< track_buffer[i].Angle <<")";
        //qDebug() << i <<": " << track_buffer[i].Distance << ", " << track_buffer[i].CourseAngle;
    }
    /*
    if(track_size>38)
    {
        for(int i=0;  i<track_size; i++)
            qDebug() << "(id, R, A) = (" <<track_buffer[i].BatchID <<", "<<track_buffer[i].Distance << ","<< track_buffer[i].Angle <<")";
    }*/
}

TrackDataParser::parserPointData_FromUDP(unsigned char *buffer, int buffer_size, TargetMessageStruct *track_buffer, int track_size)
{
    //qDebug() << "input=======================";
    Point_In elem_topush;
    for(int i=0; i<track_size; i++)
    {
        memcpy(&elem_topush, buffer+i*sizeof(Point_In), sizeof(Point_In));
        track_buffer[i].Amp =  powf(2.0f, (float)elem_topush.Amplitude);
        track_buffer[i].Angle = (float)elem_topush.Azimuth*data_precision;
        track_buffer[i].BatchID = 0;
        track_buffer[i].CourseAngle = 0;
        track_buffer[i].Distance = elem_topush.Range*data_precision;
        track_buffer[i].Radius = 0;
        track_buffer[i].Speed = elem_topush.Doppler*data_precision;
    }
}
